package com.bdmc.web.controller.task;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.task.domain.vo.TaskTeamSpanVo;
import com.bdmc.task.domain.bo.TaskTeamSpanBo;
import com.bdmc.task.service.ITaskTeamSpanService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 考勤时间段控制器
 *
 * @author bdmc
 * @date 2022-03-06
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/task/span")
public class TaskTeamSpanController extends BaseController {

    private final ITaskTeamSpanService iTaskTeamSpanService;

    /**
     * 查询考勤时间段列表
     */
    @SaCheckPermission("task:span:list")
    @GetMapping("/list")
    public TableDataInfo<TaskTeamSpanVo> list(@Validated(QueryGroup.class) TaskTeamSpanBo bo, PageQuery pageQuery) {
        return iTaskTeamSpanService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出考勤时间段列表
     */
    @SaCheckPermission("task:span:export")
    @Log(title = "考勤时间段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TaskTeamSpanBo bo, HttpServletResponse response) {
        List<TaskTeamSpanVo> list = iTaskTeamSpanService.queryList(bo);
        ExcelUtil.exportExcel(list, "考勤时间段", TaskTeamSpanVo.class, response);
    }

    /**
     * 获取考勤时间段详细信息
     */
    @SaCheckPermission("task:span:query")
    @GetMapping("/{teamSpanId}")
    public AjaxResult<TaskTeamSpanVo> getInfo(@PathVariable("teamSpanId") Integer teamSpanId) {
        return AjaxResult.success(iTaskTeamSpanService.queryById(teamSpanId));
    }

    /**
     * 新增考勤时间段
     */
    @SaCheckPermission("task:span:add")
    @Log(title = "考勤时间段", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody TaskTeamSpanBo bo) {
        return toAjax(iTaskTeamSpanService.insertByBo(bo));
    }

    /**
     * 修改考勤时间段
     */
    @SaCheckPermission("task:span:edit")
    @Log(title = "考勤时间段", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody TaskTeamSpanBo bo) {
        return toAjax(iTaskTeamSpanService.updateByBo(bo));
    }

    /**
     * 删除考勤时间段
     */
    @SaCheckPermission("task:span:remove")
    @Log(title = "考勤时间段" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{teamSpanIds}")
    public AjaxResult<Void> remove(@PathVariable Integer[] teamSpanIds) {
        return toAjax(iTaskTeamSpanService.deleteWithValidByIds(Arrays.asList(teamSpanIds), true));
    }


}
